package com.hymall.controller.wx;

import com.hymall.bean.MarketUser;
import com.hymall.bean.common.BaseRespVo;
import com.hymall.bean.common.CommonData;
import com.hymall.mapper.MarketFootprintMapper;
import com.hymall.service.wx.FootprintService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author: 牟治宇
 * @description 历史足迹
 * @date: 2022/7/19 9:36
 */

@RestController
@RequestMapping("/wx/footprint")
public class WxFootprintController {

    @Autowired
    FootprintService footprintService;

    @Autowired
    MarketFootprintMapper marketFootprintMapper;


    /**
     * @author 牟治宇
     * @description 历史足迹的list
     * @date 2022/7/19 16:54
     * @param [page, limit, userId]
     * @return com.hymall.bean.common.BaseRespVo
     */
    @GetMapping("list")
    public BaseRespVo foorprintList(Integer page,Integer limit,Integer userId){

        Subject subject = SecurityUtils.getSubject();
        MarketUser user = (MarketUser) subject.getPrincipals().getPrimaryPrincipal();
        userId = user.getId();
        Map<String,Object> data = footprintService.insertFootprint(page,limit,userId);

        BaseRespVo<Object> objectBaseRespVo = new BaseRespVo<>();
        objectBaseRespVo.setData(data);
        objectBaseRespVo.setErrno(0);
        objectBaseRespVo.setErrmsg("成功");
        return objectBaseRespVo;
    }

    /**
     * @author 牟治宇
     * @description 历史足迹删除 完全删除而非逻辑删除
     * @date 2022/7/19 16:54
     * @param [map]
     * @return com.hymall.bean.common.BaseRespVo
     */
    @PostMapping("delete")
    public BaseRespVo footprintDelete(@RequestBody Map<String, Integer> map){
        Integer id = map.get("id");
        int code = marketFootprintMapper.deleteByPrimaryKey(id);
        if (code !=1){
            return BaseRespVo.error(1,"error");
        }
        return BaseRespVo.ok();
    }

}
